<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Perfree安装-账号配置</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no"/>
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <link rel="Shortcut Icon" href="/static/public/images/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/layui@2.6.8/dist/css/layui.css">
    <link href="//cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/admin/pages/install/css/install.css?v=#(version)" rel="stylesheet"/>
</head>
<body>
<div class="p-container">
    <div class="layui-card">
        <div class="layui-card-header">
            <h2 class="install-title">Perfree</h2>
        </div>
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div class="layui-input-inline"  style="display: none;">
                    <select lay-verify="" type="hidden"></select>
                </div>
                <h3>管理员账号配置</h3>
                <div class="install-form-box">
                    <b>用户名</b>
                    <input type="text" name="account" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input install-input">
                </div>

                <div class="install-form-box">
                    <b>密码</b>
                    <input type="password" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input install-input">
                </div>

                <div class="install-form-box">
                    <b>邮箱</b>
                    <input type="email" name="email" required  lay-verify="required" placeholder="请输入邮箱地址" autocomplete="off" class="layui-input install-input">
                </div>


                <div class="button-box">
                    <button type="button" lay-submit lay-filter="addForm" class="layui-btn next-btn">完成安装</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="//cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/layui@2.6.8/dist/layui.js"></script>
<script>
    let form, element, layer;
    layui.use(['layer', 'form', 'element'], function () {
        form = layui.form;
        element = layui.element;
        layer = layui.layer;
        layer.config({
            offset: '20%'
        });
        // 表单验证
        form.verify({});
        // 表单提交
        form.on('submit(addForm)', function (data) {
            let loadIndex = layer.load("正在配置中...");
            $.ajax({
                type: "POST",
                url: "/install/addAdminUser",
                contentType: "application/json",
                data: JSON.stringify(data.field),
                success: function (data) {
                    if (data.code === 200) {
                        layer.close(loadIndex);
                        window.location.href="/login";
                    } else {
                        layer.close(loadIndex);
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error: function (data) {
                    layer.close(loadIndex);
                    layer.msg("添加失败", {icon: 2});
                }
            });
            return false;
        });
    });
</script>
</body>
</html>